<template>
	<view class="page-wrapper">
		<view v-for="addressItem in addressData" :class="{ active: addressItem.id == userChooseOrderAddress?.id}" :key="addressItem.id" class="address-item "
			@click="onSelect(addressItem)">
			<view class="top-area">
				<text class="name">{{ addressItem.receiverName }}</text>
				<text class="phone">

					{{ addressItem.receiverPhone }}</text>
				<text class="default-tag" v-if="addressItem.type==1">家</text>
				<text class="default-tag" v-if="addressItem.type==2">公司</text>
				<text class="default-tag home-tag" v-if="addressItem.type==3">学校</text>
			</view>
			<view class="address-text">{{ addressItem.addressDetail }}</view>
			<view class="bottom-area">
				<label @click.stop="setDefAddress(addressItem)">
					<checkbox color="#f60" style="transform:scale(0.8)" :checked="addressItem.isDefault || false" />
					<text class="set-def-text">设为默认</text>
				</label>
				<view class="operation-btns">
					<text class="obtn-text text1" @click.stop="deleteAddress(addressItem)">
					<text class="iconfont icon-shanchu text1" style="margin-right: 5rpx"></text >删除</text>
					<text class="obtn-text text1" @click.stop="copyText(addressItem)"><text class="iconfont icon-fuzhi"
							style="margin-right: 5rpx"></text>复制</text>
					<text class="obtn-text text1" @click.stop="edit(addressItem)"><text class="iconfont icon-bianji"
							style="margin-right: 5rpx"></text>修改</text>
				</view>
			</view>
		</view>

		<view class="add-address-btn" :style="addBtnStyles" @click="add">新增收货地址</view>
	</view>
</template>

<script>
	export default {
		name: 'JxAddressManage',
		props: {
			addressData: {
				type: Array,
				default: () => ({})
			},
			addBtnStyles: {
				type: Object,
				default: () => ({})
			},
			userChooseOrderAddress:{
				type:Object,
				default:()=>({})
			}
		},
		data() {
			return {
				current: '',
			}
		},
		methods: {
			setDefAddress(e) {
				console.log(e)
				this.$emit('set-default', e)
			},
			deleteAddress(item) {
				this.$emit('delete', item)
			},
			copyText(item) {
				uni.setClipboardData({
					data: item.addressDetail,
					success: () => {
						this.resultMessage = '复制成功';
						uni.showToast({
							title: '复制成功',
							icon: 'success'
						});
					},
					fail: () => {
						this.resultMessage = '复制失败';
						uni.showToast({
							title: '复制失败',
							icon: 'none'
						});
					}
				});
			},
			edit(item) {
				this.$emit('edit', item)
			},
			add() {
				this.$emit('add')
			},
			onSelect(item) {
				this.$emit('choose', item);
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import './iconfont.css';

	$text-color1: #333333;
	$text-color2: #666;

	page {
		background-color: #F4F4F4;
	}

	.page-wrapper {
		padding: 20rpx;
		overflow-y: scroll;
		height: calc(100vh - 200rpx - 110rpx);


		.address-item {
			width: 100%;
			height: 220rpx;
			padding: 15rpx;
			box-sizing: border-box;
			background-color: #fff;
			border-radius: 20rpx;
			margin-bottom: 20rpx;
			box-shadow: 0 20rpx 20rpx 6rpx rgba(51, 51, 51, 0.1);
			border: 4px solid white;
			.top-area {
				font-weight: bold;
				font-size: 18px;
				margin: 10rpx 0;

				.name {
					margin-right: 20rpx;
					font-size: 18px;
					font-weight: bold;
				}
				.phone{
					font-size: 16px;
				}
				.default-tag {
					position: relative;
					left: 15rpx;
					top: -5rpx;
					font-size: 10px;
					color: rgb(58, 152, 218);
					display: inline-block;
					padding: 1px 3px;
					border: 1px solid rgb(58, 152, 218);
					margin-right: 15rpx;
				}

				.home-tag {
					border: 1px solid #f60;
					color: #f60;
				}
			}

			.address-text {
				padding: 0 0 15rpx 0;
				width: 90vw;
				color: $text-color1;
				white-space: nowrap;
				/* 禁止换行 */
				font-size: 15px;
				margin-top: 5px;
				overflow: hidden;
				/* 隐藏溢出部分 */
				text-overflow: ellipsis;
				/* 使用省略号替代溢出部分 */
			}

			.bottom-area {
				margin-top: 10px;
				display: flex;
				padding-right: 0rpx;
				justify-content: space-between;
				justify-items: center;
				border-radius: 10px;

				.obtn-text {
					display: inline-block;
					padding: 6rpx 20rpx;
					margin: 0 10rpx;
					border-radius: 30rpx;
					background-color: #F4F4F4;
					color: $text-color1;
				}

				.set-def-text {
					font-size: 14px;
					color: $text-color2;
				}

				.operation-btns {
					.text1 {
						font-size: 12px;

					}
				}


			}
		}

		.address-item.active {
					border: 4px solid red;
					/* 红色边框，宽度为2px */
					box-sizing: border-box;
					/* 确保边框不会影响布局 */
				}

		.add-address-btn {
			position: fixed;
			z-index: 99;
			bottom: 120rpx;
			width: calc(100% - 30rpx);
			margin: auto;
			height: 80rpx;
			border-radius: 15rpx;
			background-color: red;
			color: #fff;
			font-size: 22px;
			text-align: center;
			line-height: 80rpx;
			letter-spacing: 4rpx;
			font-size: 14px;
		}
	}
</style>